home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / c / pro22 / cbrecpre.c < prev    next >
Text File  |  1990-06-20  |  2KB  |  74 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbrecpre.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8.  
  9. /* library headers */
  10. #include <lseq.h>
  11.  
  12. /* local headers */
  13. #include "cbase_.h"
  14.  
  15. /*man---------------------------------------------------------------------------
  16. NAME
  17.      cbrecprev - previous cbase record
  18.  
  19. SYNOPSIS
  20.      #include <cbase.h>
  21.  
  22.      int cbrecprev(cbp)
  23.      cbase_t *cbp;
  24.  
  25. DESCRIPTION
  26.      The cbrecprev function retreats the record cursor of cbase cbp to
  27.      the previous record.  If the cursor is on the first record, it is
  28.      retreated to null.
  29.  
  30.      cbrecprev will fail if one or more of the following is true:
  31.  
  32.      [EINVAL]       cbp is not a valid cbase pointer.
  33.      [CBELOCK]      cbp is not locked.
  34.      [CBENOPEN]     cbp is not open.
  35.  
  36. SEE ALSO
  37.      cbrcursor, cbrecfirst, cbreclast, cbrecnext.
  38.  
  39. DIAGNOSTICS
  40.      Upon successful completion, a value of 0 is returned.  Otherwise,
  41.      a value of -1 is returned, and errno set to indicate the error.
  42.  
  43. ------------------------------------------------------------------------------*/
  44. int cbrecprev(cbp)
  45. cbase_t *cbp;
  46. {
  47.     /* validate arguments */
  48.     if (!cb_valid(cbp)) {
  49.         errno = EINVAL;
  50.         return -1;
  51.     }
  52.  
  53.     /* check if not open */
  54.     if (!(cbp->flags & CBOPEN)) {
  55.         errno = CBENOPEN;
  56.         return -1;
  57.     }
  58.  
  59.     /* check if not locked */
  60.     if (!(cbp->flags & CBLOCKS)) {
  61.         errno = CBELOCK;
  62.         return -1;
  63.     }
  64.  
  65.     /* retreat cursor to previous record */
  66.     if (lsprev(cbp->lsp) == -1) {
  67.         CBEPRINT;
  68.         return -1;
  69.     }
  70.  
  71.     errno = 0;
  72.     return 0;
  73. }
  74.